<?php

require_once($common_data_server.'modules/shop/shop.php'); 


/**
 * Каталог товаров с динамическими характеристиками
 * @author  Холодий Андрей
 * @version 1.1
 * @copyright Copyright 2003, РБК СОФТ
 * @package E-shop
 * @subpackage catalogue
 */
class dynamic_catalogue extends shop 
{
   
   
function content_init()
{
	#-----------------------------------------------------
	/*
		if ( is_array($this->q_param) && 0 )
		{  	
			$keys = array_keys($this->q_param);
			$index = sizeof($keys);
			for($i=0; $i<$index; $i++)
			{
				$this->q_param[$keys[$i]] = $this->q_param[$keys[$i]]."'";
			}
		} 
	*/
	#-------------------------------------------------------

	global $common_data_server;
	$this -> publishedCurrency 	= $this -> getPublishedCurrency();
	$this -> path_tmpl 			= "{$common_data_server}module_templates/dynamic_catalogue/{$this -> view_param['template']}/";

	// Проверка переданных параметров
	if (!is_numeric($this -> q_param['id_pt_'])) 		$this -> q_param['id_pt_'] = 0;
	if (!is_numeric($this -> q_param['ord'])) 			$this -> q_param['ord'] = 0;
	if (!is_numeric($this -> q_param['price_low']))		$this -> q_param['price_low'] = '';
	if (!is_numeric($this -> q_param['price_high']))	$this -> q_param['price_high'] = '';
	if (!is_numeric($this -> q_param['id'])) 			$this -> q_param['id'] = 0;
	else 												$filename = 'detail';    
	if ($this -> q_param['action'] == 'compare') 		$filename = 'compare';    

	$filename = ($filename ? $filename : $this -> view_param['view_mode']).'.vtmpl';

	if (!file_exists($this -> path_tmpl.$filename)) {
		$this -> body = "Шаблон отсутствует: {$this -> path_tmpl}{$filename}";
		return 0;
	}

	$this -> tmpl = new vlibTemplate();
	$this -> tmpl -> newTemplate($this -> path_tmpl.$filename);

	// Сравнение товаров
	if ($this -> q_param['action'] == 'compare') 				$this -> modeProductCompare();

	// Карточка товара
	elseif ($this -> q_param['id']) 							$this -> modeProductDetail();

	// Вариант использования "Список товаров"
	elseif ($this -> view_param['view_mode'] == 'list') 		$this -> modeProductList();	   	   

	// Вариант использования "Меню типов"
	elseif ($this -> view_param['view_mode'] == 'menu_type') 	$this -> modeMenuType();	   	   

	// Вариант использования "Поиск ..."
	elseif (strstr($this -> view_param['view_mode'], 'search')) $this -> modeProductSearch();

	$this -> tmpl -> setVar('TAREA', $this -> tarea_id);

	if ($this -> is_print) 	$this -> tmpl -> setVar('is_print', 1);
	else 					$this -> tmpl -> setVar('printable_url','printable.php?'.make_query_string(array('print' => '1')));

	$this -> body = $this -> tmpl -> grab();
}


  
/**
 * Вариант использования "Меню типов"
 */
function modeMenuType()
{ 
	$this_tarea_id = $this -> tarea_id;
	$catalog_tarea_id = $this -> view_param['go_to_page']
		? $this -> getTAreaID($this -> view_param['go_to_page'])
		: $this -> getTAreaID($this -> page_id);
	$this -> tarea_id = $this_tarea_id;
	
	$this -> tmpl -> setVar('ALL_URL',  'index.php?'.make_query_string(array("pt_id_{$catalog_tarea_id}" => '', "pt_id_{$this -> tarea_id}" => '', "id{$catalog_tarea_id}" => '')));
	$this -> tmpl -> setVar('ALL_SELECTED', !intval($this -> q_param['pt_id_']) ? 1 : 0);

	//Выборка всех типов товаров В БЛОКЕ
	$productTypeIDs = sql_select("
		select distinct P.PRODUCT_TYPE_ID as ID
		from PRODUCT P,CONTENT_MAP CM
		where CM.INF_BLOCK_ID = ".intval($this -> block_id)." and P.CONTENT_ID = CM.CONTENT_ID 
			and P.LANG_ID = ".intval($this -> lang_id)." and P.VERSION = ".intval($this -> version)
	);
	$productTypeArr = sql_select("
		select * 
		from PRODUCT_TYPE 
		where LANG_ID = ".intval($this -> lang_id)." and PRODUCT_TYPE_ID in (".array_make_in($productTypeIDs, 'ID').") 
		order by PRODUCT_TYPE_ORDER
	");
	for ($i = 0; $i < count($productTypeArr); $i++) {
		$productTypeArr[$i]['URL'] = 'index.php?'.make_query_string(array("pt_id_{$catalog_tarea_id}" => $productTypeArr[$i]['PRODUCT_TYPE_ID'], "pt_id_{$this -> tarea_id}" => $productTypeArr[$i]['PRODUCT_TYPE_ID'], "id{$catalog_tarea_id}" => ''));		
		$productTypeArr[$i]['SELECTED'] = ($this -> q_param['pt_id_'] == $productTypeArr[$i]['PRODUCT_TYPE_ID'] ? 1 : 0);
	}

	$this -> tmpl -> setLoop('_product_type_loop', $productTypeArr);
}


/**
 * Вариант использования "Поиск ..."
 */
function modeProductSearch()
{ 
	// Поиск по разделу
	if ($this -> view_param['view_mode'] == 'search_by_category')
	{
		if ($this -> q_param['PAGE_ID']) $pageID = intval($this -> q_param['PAGE_ID']);
		else $pageID = $this -> page_id;

		if ($this -> q_param['INF_BLOCK_ID']) $infBlockID = $this -> q_param['INF_BLOCK_ID'];
		else $infBlockID = $this -> block_id;

		$this -> block_id 	= $infBlockID;
		$this -> page_id 	= $pageID;

		$page = sql_select("
			select PAGE.NAME as PAGE_NAME 
			from PAGE 
			where PAGE_ID = ".intval($this -> page_id)." and LANG_ID = ".intval($this -> lang_id)." and VERSION = ".intval($this -> version)."
		");

		$this -> tmpl -> setVar('PAGE_ID', 		$this -> page_id);
		$this -> tmpl -> setVar('INF_BLOCK_ID', $this -> block_id);
		$this -> tmpl -> hash2vlib($page[0]);
	}

	// Расширенный и быстрый поиски
	if ($this -> view_param['view_mode'] == 'fast_search' || $this -> view_param['view_mode'] == 'extend_search')
	{
		//Выборка всех типов товаров ВООБЩЕ
		$productTypeArr = sql_select("select * from PRODUCT_TYPE where LANG_ID = ".intval($this -> lang_id)." order by PRODUCT_TYPE_ORDER");
		for ($i = 0; $i < count($productTypeArr); $i++) {
			$productTypeArr[$i]['_url'] = "pt_id_{$this -> tarea_id}={$productTypeArr[$i]['PRODUCT_TYPE_ID']}";//make_query_string(array("pt_id_{$this -> tarea_id}" => $productTypeArr[$i]['PRODUCT_TYPE_ID']));		
			$productTypeArr[$i]['_selected'] = ($this -> q_param['pt_id_'] == $productTypeArr[$i]['PRODUCT_TYPE_ID'] ? 1 : 0);
		}

		$this -> tmpl -> setLoop('_product_type_loop', $productTypeArr);

		// Определяет область поиска по каталогу. В данном случае поиск идет по всем ЭК модуля "Каталог товаров".
		$blockSet = $this -> getBlockSetForModule('dynamic_catalogue');
		if (!$blockSet || ($this -> view_param['view_mode'] == 'extend_search' && !$this -> q_param['pt_id_'])) return 0;
	}
	else
	{
		//Выборка всех типов товаров В БЛОКЕ
		$productTypeArr = sql_select("
			select distinct P.PRODUCT_TYPE_ID
			from PRODUCT P, CONTENT_MAP CM
			where
			CM.INF_BLOCK_ID = ".intval($this -> block_id)." and P.CONTENT_ID = CM.CONTENT_ID 
			and P.LANG_ID = ".intval($this -> lang_id)." and P.VERSION = ".intval($this -> version)."
		");
		$blockSet = $this -> block_id;
	}

	if (empty($productTypeArr) && !$this -> q_param['pt_id_']) return 0;

	if ($this -> view_param['view_mode'] == 'extend_search' || $this -> view_param['view_mode'] == 'search_by_category')
		$propertySQL = $this -> showPropertyForExtendSearch($productTypeArr, $blockSet);

	if ($this -> q_param['price_low']) 	$priceLowSQL 	= 'P.PRICE > '.htmlspecialchars(($this -> q_param['price_low']*$this -> publishedCurrency['VALUE']), ENT_QUOTES).' and ';
	if ($this -> q_param['price_high']) $priceHighSQL 	= 'P.PRICE < '.htmlspecialchars(($this -> q_param['price_high']*$this -> publishedCurrency['VALUE']), ENT_QUOTES).' and ';

	$selectSQL 	= "
		select distinct " . getDistinctFields('PRODUCT', 'P')."
	";
		//			P.VERSION,
		//			P.TITLE,
		//			P.CONTENT_ID,
		//			P.STATE_ID,
		//			P.LANG_ID,
		//			P.PRODUCT_TYPE_ID,
		//			P.IMAGE_SMALL,
		//			P.IMAGE,
		//			P.PRICE,
		//			P.TIME_STAMP ";

	$fromSQL 	= "
		from CONTENT_MAP CM, PRODUCT P
	";

	$whereSQL	= "
		where
			CM.INF_BLOCK_ID in ({$blockSet}) and CM.CONTENT_ID = P.CONTENT_ID 
			and P.LANG_ID = ".intval($this -> lang_id)." and
		".

		($this -> q_param['title'] 			? "(P.TITLE like '%".htmlspecialchars($this -> q_param['title'], ENT_QUOTES)."%' or 
											 P.DESCRIPTION like '%".htmlspecialchars($this -> q_param['title'], ENT_QUOTES)."%') and " 	: '').
		$priceLowSQL.
		$priceHighSQL.
		($this -> q_param['pt_id_'] 		? "P.PRODUCT_TYPE_ID = ".intval($this -> q_param['pt_id_'])." and " 		: '').
		($propertySQL 						? "$propertySQL and " 											: '').

		"	P.VERSION = {$this -> version}
	";

	//Если заданы параметры для поиска и найденны товары
	if ( ($this -> q_param['pt_id_'] && $this -> view_param['view_mode'] != 'extend_search') 
		|| ($propertySQL && $this -> view_param['view_mode'] != 'fast_search') 
		|| $this -> q_param['title'] 
		|| $this -> q_param['price_low'] 
		|| $this -> q_param['price_high'] )
	{
		if ($this -> view_param['view_mode'] == 'fast_search') 
			$productTypeArr = sql_select("select distinct P.PRODUCT_TYPE_ID ".$fromSQL.$whereSQL);

		$commonPropertyArr 	= $this -> getCommonPropertyArr($productTypeArr);
		$sqlArr 			= $this -> getSQLArr($commonPropertyArr, $selectSQL, $fromSQL, $whereSQL, $orderSQL);

		if (!$this -> showProductList($commonPropertyArr, $sqlArr['selectSQL'], $sqlArr['fromSQL'], $sqlArr['orderSQL'])) $this -> tmpl -> setVar('_noResults', 1);
	}
	elseif (isset($this -> q_param['title']))
	{
		$this -> tmpl -> setVar('_noParams', 1);
	}
	
	if ($this -> view_param['go_to_page']) 
		$this -> tarea_id = $this -> getTAreaID($this -> view_param['go_to_page']);
	else 
		$this -> tarea_id = $this -> getTAreaID($this -> page_id);

	if (!$this -> q_param['searchType']) 			$this -> tmpl -> setVar('checkedAnd', ' checked');
	elseif ($this -> q_param['searchType'] == 'or')	$this -> tmpl -> setVar('checkedOr',  ' checked');
	elseif ($this -> q_param['searchType'] == 'and')$this -> tmpl -> setVar('checkedAnd', ' checked');

	$this -> tmpl -> setVar('publishedCurrency', 	$this -> publishedCurrency['NAME_SHORT']);
	$this -> tmpl -> setVar('TITLE', 				$this -> q_param['title']);
	$this -> tmpl -> setVar('_form_url', 			$this -> go_to_page($this -> view_param['go_to_page']));
	$this -> tmpl -> setVar('_price_low', 			$this -> q_param['price_low']);
	$this -> tmpl -> setVar('_price_high',			$this -> q_param['price_high']);
	$this -> tmpl -> setVar('_pt_id',				$this -> q_param['pt_id_']);
}

  
  /********************** Сравнение товаров ******************************************/
  function modeProductCompare() {

   	session_start();	   

	//Создание списка сравниваемых товаров
	if ($this -> q_param['module'] == 'basket' || empty($_SESSION['compare_product_arr']))
		$_SESSION['compare_product_arr'] = $this -> q_param['compare_product_arr'];
	
	else 
		//Удаление товара из списка сравнений
		if (!empty($this -> q_param['del_product_arr'])) {
			for ($i = 0; $i < count($_SESSION['compare_product_arr']); $i++)
				for ($j = 0; $j < count($this -> q_param['del_product_arr']); $j++)
		   			if ($_SESSION['compare_product_arr'][$i] == $this -> q_param['del_product_arr'][$j])
		   				array_splice($_SESSION['compare_product_arr'], $i, 1);
		//Добавление товаров в список сравнений
		} elseif (!empty($this -> q_param['compare_product_arr']))
			for ($i = 0; $i < count($this -> q_param['compare_product_arr']); $i++) 
				if (!in_array($this -> q_param['compare_product_arr'][$i], $_SESSION['compare_product_arr']))
					$_SESSION['compare_product_arr'][] = $this -> q_param['compare_product_arr'][$i];	
	
	//Список сравниваемых товаров пуст
	if (empty($_SESSION['compare_product_arr'])) return false;

	foreach ($_SESSION['compare_product_arr'] as $v)
	 	$productSet .= $v.", ";	   	 
	$productSet = substr($productSet, 0, strlen($productSet) - 2);
	
	//Выбор сравниваемых товаров
	$productArr = sql_select("select * from PRODUCT
							  where
							     CONTENT_ID in ({$productSet}) and
							     LANG_ID = ".intval($this -> lang_id)." and
							     VERSION = ".intval($this -> version));
	
	$productTypeSet = $this -> getSet($productArr, 'PRODUCT_TYPE_ID');

	$oneValueArr = array();
	$setValueArr = array();
	
	//Выбор множества значений  характеристик типа "значение" - 0
	$oneValueArr = sql_select("select
								      PP.CONTENT_ID,
								      PR.PROPERTY_ID,
								      PP.VALUE_PROPERTY as VALUE
								from
								    PROPERTY PR,
								    PRODUCT_PROPERTY PP,
								    PRODUCT_TYPE_PROPERTY PTPR
								where
								     PP.CONTENT_ID in ({$productSet}) and
								     PP.PROPERTY_ID  = PR.PROPERTY_ID and
								     PR.LANG_ID = ".intval($this -> lang_id)." and
								     PR.PROPERTY_TYPE = 0 and
								     PR.PROPERTY_ID = PTPR.PROPERTY_ID and
								     PTPR.PRODUCT_TYPE_ID in ({$productTypeSet})");
	
	//Выбор множества характеристик типа "значение из списка", "набор" - (1, 2)
	$firstTypePropertyArr = sql_select("select distinct
										      PR.PROPERTY_ID
										from
										    PROPERTY PR,
										    PRODUCT_PROPERTY PP,
										    PRODUCT_TYPE_PROPERTY PTPR
										where
										     PP.CONTENT_ID in ({$productSet}) and
										     PP.PROPERTY_ID  = PR.PROPERTY_ID and
										     PR.LANG_ID = ".intval($this -> lang_id)." and
										     PR.PROPERTY_TYPE in (1,2) and
										     PR.PROPERTY_ID = PTPR.PROPERTY_ID and
										     PTPR.PRODUCT_TYPE_ID in ({$productTypeSet})");
	
	$setPropertyId = $this -> getSet($firstTypePropertyArr, 'PROPERTY_ID');
	
	if (!empty($firstTypePropertyArr) &&
	   //Выбор множества значений характеристик "значение из списка", "набор" - (1, 2)
	   $setValueArrTemp = sql_select("select
										      PP.CONTENT_ID,
										      PP.PROPERTY_ID,
										      PV.NAME as VALUE
										from
										    PRODUCT_PROPERTY PP,
										    PRODUCT_PROPERTY_VALUE PPV,
										    PROPERTY_VALUE PV
										where
										     PP.CONTENT_ID in ({$productSet}) and
										     PP.PROPERTY_ID in ({$setPropertyId}) and
										     PP.PRODUCT_PROPERTY_ID = PPV.PRODUCT_PROPERTY_ID and
										     PPV.PROPERTY_VALUE_ID = PV.PROPERTY_VALUE_ID and
										     PV.LANG_ID = ".intval($this -> lang_id)."
										order by
										      PP.PROPERTY_ID,
										      PP.CONTENT_ID"))
		//Нормализация массива, если в нем присутствуют характеристики типа "набор"
		foreach ($setValueArrTemp as $propertyValue) {
			if ($prevRow['CONTENT_ID'] == $propertyValue['CONTENT_ID'] && 
				$prevRow['PROPERTY_ID'] == $propertyValue['PROPERTY_ID'] && $prevRow)
				 $setValueArr[count($setValueArr) - 1]['VALUE'] .= ', '.$propertyValue['VALUE']; 
			else $setValueArr[] = $propertyValue; 
			$prevRow = $propertyValue;
		}
	//Массив значений ОБЩИЙ для характеристик всех типов
	$propertyValueArr = array_merge($oneValueArr, $setValueArr);

	//Упорядочивается массив товаров
	foreach ($_SESSION['compare_product_arr'] as $compareProductID)
	 	foreach ($productArr as $product)
	 		if ($product['CONTENT_ID'] == $compareProductID) {
	 			
	 			$product['productURL'] = $this -> getProductUrl($product['CONTENT_ID']);
	 			$newProductArr[] = $product;
	 		}

	$this -> tmpl -> setLoop('PRODUCT_LOOP', $newProductArr);

	//Выбор всех характеристик и упорядочивание оных
	if ($propertyArr = sql_select ("select 
								      PTPR.PROPERTY_ID,
								      PRG.NAME as GROUP_NAME,
								      PR.NAME,
								      PR.PROPERTY_TYPE,
								      PR.MESURE_UNITS
								from
								    PRODUCT_TYPE_PROPERTY PTPR,
								    PROPERTY_GROUP PRG,								    
								    PROPERTY PR
								where
								     PTPR.PRODUCT_TYPE_ID in ({$productTypeSet}) and
								     PTPR.PROPERTY_ID = PR.PROPERTY_ID and
								     PRG.PROPERTY_GROUP_ID = PR.PROPERTY_GROUP_ID and
								     PR.PROPERTY_TYPE in (0,1,2) and							     
								     PR.LANG_ID = ".intval($this -> lang_id)."
								group by PTPR.PROPERTY_ID,
									PRG.NAME,
									PR.NAME,
									PR.PROPERTY_TYPE,
									PR.MESURE_UNITS,
									PRG.GROUP_ORDER,
									PR.PROPERTY_ORDER
								order by PRG.GROUP_ORDER, PR.PROPERTY_ORDER")) {
	
		// Добавление названий групп характеристик
		for ($i = 0; $i < count($propertyArr); $i++){
			if ($propertyArr[$i]['GROUP_NAME'] != $propertyArr[$i-1]['GROUP_NAME'])
				$propertyLoop[] = array('TD_LOOP' => array(array('NAME' => $propertyArr[$i]['GROUP_NAME'], 'IS_GROUP' => 1)));
			$propertyLoop[] = array('TD_LOOP' => array($propertyArr[$i]));
			$colspan = count($propertyArr[$i]) + 1;
		}
	
		// Добавление значений характеристик
		foreach ($_SESSION['compare_product_arr'] as $compareProductID) {
	
			for ($i = 0; $i < count($propertyLoop); $i++) {
	
				 // Пропускается строка с названием группы характеристик
				 if ($propertyLoop[$i]['TD_LOOP'][0]['IS_GROUP']) {
		    		$propertyLoop[$i]['TD_LOOP'][0]['COLSPAN'] = $colspan;
				 	$i++;
				 }

				 // Достается значение характеристики товара
				 $value = '';
				 foreach ($propertyValueArr as $propertyValue)
			 		if ($propertyValue['CONTENT_ID'] == $compareProductID && 
			 			$propertyValue['PROPERTY_ID'] == $propertyLoop[$i]['TD_LOOP'][0]['PROPERTY_ID']) $value = $propertyValue['VALUE'];

			 	$propertyLoop[$i]['TD_LOOP'][] = array('NAME' => $value);
			}
		}

		$this -> tmpl -> setLoop('PROPERTY_LOOP', $propertyLoop);
	}
  }
  
  /********************** Вариант использования "Список товаров" ***********/
  function modeProductList() {
	   
	//Выборка всех типов товар в блоке
	$productTypeArr = 
		sql_select("select distinct
					       P.PRODUCT_TYPE_ID
					from
					    PRODUCT P,
					    CONTENT_MAP CM
					where
					     CM.INF_BLOCK_ID = ".intval($this -> block_id)." and
					     P.CONTENT_ID = CM.CONTENT_ID and
					     P.LANG_ID = ".intval($this -> lang_id)." and
					     P.VERSION = ".intval($this -> version));
	
	if (count($productTypeArr) <= 0) return false;
	
	$commonPropertyArr = $this -> getCommonPropertyArr($productTypeArr);
	$sqlArr 		   = $this -> getSQLArr($commonPropertyArr);

	$this -> showProductList($commonPropertyArr, $sqlArr['selectSQL'], $sqlArr['fromSQL'], $sqlArr['orderSQL']);
  }

  /**************************** Карточка товара **************************************************/
  function modeProductDetail() {

	if (!$product = 
			sql_select("select * from  PRODUCT
					 	where 
						     CONTENT_ID = ".intval($this -> q_param['id'])." and
						     LANG_ID = ".intval($this -> lang_id)." and
						     VERSION = ".intval($this -> version))) return false;
	
	$basketTAreaID = $this -> getModuleTAreaID('basket');
	
	//Еслие есть связанные товаров
	if ($slaveProductArr = 
		sql_select("select distinct
						PL.*, " . getDistinctFields('PRODUCT', 'P2') . "
					from
						PRODUCT P,
						PRODUCT_LINK PL,
						PRODUCT P2
					where
						PL.MASTER_CONTENT_ID = ".intval($this -> q_param['id'])." and
						PL.MASTER_CONTENT_ID = P.CONTENT_ID and
						P2.CONTENT_ID = PL.SLAVE_CONTENT_ID and
						PL.SLAVE_CONTENT_ID <> ".intval($this -> q_param['id'])." and
						P2.VERSION = ".intval($this -> version)." and
						P2.LANG_ID = ".intval($this -> lang_id)." 
					order by PL.LINK_TYPE_ID"))

		foreach ($slaveProductArr as $slaveProduct) {
			$slaveProduct['PRICE'] = $this -> getPrice($slaveProduct['PRICE']);
			$slaveProduct['_productURL'] = $this -> getProductUrl($slaveProduct['SLAVE_CONTENT_ID']);
			$slaveProduct['_inBasketURL'] = make_query_string(array("in_id{$basketTAreaID}" => $slaveProduct['CONTENT_ID'], "wait_id{$basketTAreaID}" => ''));
			$slaveProduct['_inWaitURL'] =  make_query_string(array("wait_id$basketTAreaID" => $slaveProduct['CONTENT_ID'], "in_id{$basketTAreaID}" => ''));
			if ($slaveProduct['_productURL'])
				if ($slaveProduct['LINK_TYPE_ID'] == 1) $productLinkArr1[] = $slaveProduct;
				elseif ($slaveProduct['LINK_TYPE_ID'] == 2) $productLinkArr2[] = $slaveProduct;
				elseif ($slaveProduct['LINK_TYPE_ID'] == 3) $productLinkArr3[] = $slaveProduct;
		}
	//Если есть у товара динамические характеристики
	if ($propertyArr = 
		sql_select("select
					      PP.VALUE_PROPERTY as ONE_VALUE,
					      P.NAME as PROPERTY_NAME,
					      P.MESURE_UNITS as MESURE_UNITS,
					      P.PROPERTY_TYPE as PROPERTY_TYPE,
					      PP.PRODUCT_PROPERTY_ID as PRODUCT_PROPERTY_ID,
					      PG.NAME as CURRENT_GROUP
					from
					    PRODUCT_PROPERTY PP,
					    PROPERTY P,
					    PROPERTY_GROUP PG,
					    PRODUCT_TYPE_PROPERTY PTPR
					where
					     PP.CONTENT_ID = ".intval($product[0]['CONTENT_ID'])." and
					     P.LANG_ID = ".intval($this -> lang_id)." and
					     PP.PROPERTY_ID = P.PROPERTY_ID and
					     PTPR.PROPERTY_ID = P.PROPERTY_ID and
					     PTPR.PRODUCT_TYPE_ID = ".intval($product[0]['PRODUCT_TYPE_ID'])." and
					     P.PROPERTY_GROUP_ID = PG.PROPERTY_GROUP_ID
					order by
					      PG.GROUP_ORDER,
					      P.PROPERTY_ORDER")) {
		
		$productPropertySet = $this -> getSet($propertyArr, 'PRODUCT_PROPERTY_ID');
		//Все хар-ки: 'значение из списка' или 'набор'
		$valueArr = 
			sql_select("select
						      PPV.PRODUCT_PROPERTY_ID,
						      PV.PROPERTY_ID,
						      PV.NAME as PROPERTY_VALUE,
						      PV.IMAGE as PROPERTY_IMAGE
						from
						    PRODUCT_PROPERTY_VALUE PPV,
						    PROPERTY_VALUE PV
						where
						     PPV.PRODUCT_PROPERTY_ID in ({$productPropertySet}) and
						     PPV.PROPERTY_VALUE_ID = PV.PROPERTY_VALUE_ID and
						     PV.LANG_ID = ".intval($this -> lang_id)."
						order by PV.PROPERTY_ID, PV.PROPERTY_VALUE_ORDER");
						
		for ($i = 0; $i < count($propertyArr); $i++) {
			//Тип хар-ки: 'значение'
			if (!$propertyArr[$i]['PROPERTY_TYPE'] && $propertyArr[$i]['ONE_VALUE']) 
				$propertyArr[$i]['VALUE_LOOP'][] = array(PROPERTY_VALUE => $propertyArr[$i]['ONE_VALUE']);
			//Тип хар-ки: 'значение из списка' или 'набор'
			elseif ($propertyArr[$i]['PROPERTY_TYPE'] && !empty($valueArr))
				foreach ($valueArr as $value)
					if ($propertyArr[$i]['PRODUCT_PROPERTY_ID'] == $value['PRODUCT_PROPERTY_ID']) $propertyArr[$i]['VALUE_LOOP'][] = $value;
	        //Группировка характеристик при выводе
			if ($propertyArr[$i-1]['CURRENT_GROUP'] != $propertyArr[$i]['CURRENT_GROUP']) $propertyArr[$i]['GROUP_NAME'] = $propertyArr[$i]['CURRENT_GROUP'];
		}
	}
	//Редактирование карточки товара
	$product[0]['PRICE'] = $this -> getPrice($product[0]['PRICE']);
	$product[0]['_publishedCurrency'] = ($this -> publishedCurrency['NAME_SHORT'] ? $this -> publishedCurrency['NAME_SHORT'] : "y.e.");
	$product[0]['_productLinkLoop1'] = $productLinkArr1;
	$product[0]['_productLinkLoop2'] = $productLinkArr2;
	$product[0]['_productLinkLoop3'] = $productLinkArr3;
	$product[0]['_inBasketURL'] = make_query_string(array("in_id{$basketTAreaID}" => $product[0]['CONTENT_ID'], "wait_id{$basketTAreaID}" => '')); 
	$product[0]['_waitBasketURL'] = make_query_string(array("wait_id{$basketTAreaID}" => $product[0]['CONTENT_ID'], "in_id{$basketTAreaID}" => ''));						
	$product[0]['PROPERTY_LOOP'] = $propertyArr;
	
	$this -> tmpl -> hash2vlib($product[0]);
  }

  /********************** getHeaderArr ****************************************/
  function getHeaderArr($commonPropertyArr) {
  /*
  	Заполняет массив заголовков таблицы
  */

	$headerArr = array();
	//Заголовки характеристик с единицами измерений
	foreach ($commonPropertyArr as $row) {
		if ($row['PROPERTY_TYPE'] == 0 || $row['PROPERTY_TYPE'] == 1) $row['URL'] = 1;
		$headerArr[] = $row;
	}
	
	if ($headerArr) $this -> tmpl -> setLoop('propertyHeaderLoop', $headerArr);
	
	array_unshift($headerArr, 
		array(HEADER_NAME => 'N'), 
		array(HEADER_NAME => 'Изображение'),
		array(HEADER_NAME => 'Название', URL => 1) 
	);
	array_push($headerArr, 
		array(HEADER_NAME => 'Цена', 
			  MESURE_UNITS => $this -> publishedCurrency['NAME_SHORT'],
			  URL => 1),
		array(HEADER_NAME => 'В корзину'),
		array(HEADER_NAME => 'Отложить'),
		array(HEADER_NAME => 'Сравнить'));

	return $headerArr;
  }
    
  /**************************** showProductList **************************************/
  function showProductList($commonPropertyArr, $selectSQL, $fromSQL, $orderSQL) {
  /* 
  	Выводит список товаров.
  */

	$index 				= 1;	// порядковый номер в списке
	$from 				= -1; 	// CONTENT_ID первого товара
	
	// Модификация для поиска.
	if (strstr($this -> view_param['view_mode'], 'search')) {
		
		$productQuantity = sql_select($selectSQL.$fromSQL.$orderSQL);
		$productQuantity[0]['QTY'] = count($productQuantity);
		
	} else $productQuantity = sql_select("select distinct COUNT(*) as QTY $fromSQL");

	// Навигация 
	if ($productQuantity[0]['QTY'] > $this -> view_param['num_per_page'] && 
		$this -> view_param['num_per_page'] > 0 &&
		!$this -> is_print) {

		if ($this -> q_param['from']) {
			$from = ($this -> q_param['from'] - 1)*$this -> view_param['num_per_page'];
			$index = $from + 1;
		} else $from = 0;

		$this -> tmpl -> setVar('NAVIGATION', page_navigation(
								$this -> view_param['num_per_page'], 
								$productQuantity[0]['QTY'],
								"from{$this -> tarea_id}",
								"{$this -> path_tmpl}page_navigation.vtmpl",
								array('in_id', 'wait_id')
							   )
		);
	}
		
	// Формируется limit SQL-запроса
	if ($from >= 0) $limitSQL = " limit ".intval($from).", ".intval($this -> view_param['num_per_page']);

	$productArr = sql_select($selectSQL.$fromSQL.$orderSQL.$limitSQL);
	
	if (!$productArr) return false;

	//Заполняются столбцы значений характеристик
	$productSet = $this -> getSet($productArr, 'CONTENT_ID');		
	for ($i = 0; $i < count($commonPropertyArr); $i++) {
		if (!$commonPropertyArr[$i]['PROPERTY_TYPE']) 
			$sSQL = "select
					      PP.CONTENT_ID,
					      PP.VALUE_PROPERTY as VALUE
					from
					    PRODUCT_PROPERTY PP,
					    PROPERTY P
					where
					     PP.CONTENT_ID in ({$productSet}) and
					     PP.PROPERTY_ID = ".intval($commonPropertyArr[$i]['PROPERTY_ID'])." and
					     P.LANG_ID = ".intval($this -> lang_id)." and
					     PP.PROPERTY_ID = P.PROPERTY_ID";
		else
			$sSQL = "select distinct
					       PP.CONTENT_ID,
					       PV.NAME as VALUE
					from
					    PRODUCT_PROPERTY PP,
					    PRODUCT_PROPERTY_VALUE PPV,
					    PROPERTY_VALUE PV
					where
					     PP.CONTENT_ID in ({$productSet}) and
					     PP.PROPERTY_ID = ".intval($commonPropertyArr[$i]['PROPERTY_ID'])." and
					     PV.LANG_ID = ".intval($this -> lang_id)." and
					     PPV.PRODUCT_PROPERTY_ID = PP.PRODUCT_PROPERTY_ID and
					     PPV.PROPERTY_VALUE_ID = PV.PROPERTY_VALUE_ID";
		$commonPropertyArr[$i]['VALUE_ARRAY'] = sql_select($sSQL);  
	}
	
	$basketTAreaID = $this -> getModuleTAreaID('basket');
	// Заполняется таблица со списком товаров
	for ($i = 0; $i < count($productArr); $i++) {
		
		$valueArr = array();
		// Характеристики
		foreach ($commonPropertyArr as $property) {
			$propertyValue = '';
			foreach ($property['VALUE_ARRAY'] as $value)
				if ($value['CONTENT_ID'] == $productArr[$i]['CONTENT_ID'])
					if (!$propertyValue) $propertyValue = $value['VALUE'];
					else $propertyValue .= ', '.$value['VALUE'];
			$valueArr[] = array(VALUE => $propertyValue);
		}

		// Значения характеристик
		if ($valueArr)  $productArr[$i]['PROPERTY_VALUE_LOOP'] 	= $valueArr;
		
		// Статические значения товаров
		$productArr[$i]['index'] 		= $index;
		$productArr[$i]['PRICE'] 		= $this -> getPrice($productArr[$i]['PRICE']);
		$productArr[$i]['productURL'] 	= $this -> getProductUrl($productArr[$i]['CONTENT_ID']);
		$productArr[$i]['putDownURL'] 	= // В корзину
							make_query_string(array("in_id{$basketTAreaID}"   => $productArr[$i]['CONTENT_ID'], 
													"wait_id{$basketTAreaID}" => ''));
		$productArr[$i]['putOffURL'] 	= // Отложить
							make_query_string(array("in_id{$basketTAreaID}"   => '', 
													"wait_id{$basketTAreaID}" => $productArr[$i]['CONTENT_ID']));
		$index++;
	}

	$this -> tmpl -> setVar ('publishedCurrency', 	$this -> publishedCurrency['NAME_SHORT']);
	$this -> tmpl -> setLoop('PRODUCT_LOOP', 		$productArr);	

	return true;
  }

  /**************************** showPropertyForExtendSearch **************************************/
  function showPropertyForExtendSearch($productTypeArr, $blockSet) {
  /* 
  	Выводит список характеристик для расширенного поиска.
  */

	//Выбор общих характеристик и упорядочивание оных у которых уставнолен флаг "Участие в поиске"
	$searchPropertyArr = $this -> getCommonPropertyArr($productTypeArr, 'IS_IN_SEARCH');

	//Достаются значение для характеристик типов: 'значение из списка' и 'набор'
	if (!empty($searchPropertyArr))
		$valueArr = sql_select("select
								      PROPERTY_VALUE_ID as PV_ID,
								      NAME as PV_NAME,
								      PROPERTY_ID
								from
								    PROPERTY_VALUE
								where
								     PROPERTY_ID in (".$this-> getSet($searchPropertyArr,'PROPERTY_ID').") and
								     LANG_ID = ".intval($this -> lang_id)."
								order by NAME");	
	//хранит кол-во выбранных характеристик
	$_flag_ = 0;
	$_count0_ = 0; //Кол-во выбранных характеристик типа "строка"
	$_count12_ = 0; //Кол-во выбранных характеристик типа "значение из списка" или "набор"
	// Подготовка к выводу характеристик в поиске
	for ($j = 0; $j < count($searchPropertyArr); $j++) 
		if (!$searchPropertyArr[$j]['PROPERTY_TYPE'])
			//Числовое значение
			if ($searchPropertyArr[$j]['IS_NUMBER']) {
				$intervalStr = '';
				if (is_numeric($this -> q_param["low_{$searchPropertyArr[$j]['PROPERTY_ID']}_"])) {
					//Сохраняется параметр поиска
					$searchPropertyArr[$j]['_low_value'] = 
						htmlspecialchars($this -> q_param["low_{$searchPropertyArr[$j]['PROPERTY_ID']}_"], ENT_QUOTES);
					//Формируется SQL 
					$intervalStr = 
						varcharToFloat('PP.VALUE_PROPERTY') .' > '.htmlspecialchars($this -> q_param["low_{$searchPropertyArr[$j]['PROPERTY_ID']}_"]);
				}
				if (is_numeric($this -> q_param["high_{$searchPropertyArr[$j]['PROPERTY_ID']}_"])) {
					//Сохраняется параметр поиска
					$searchPropertyArr[$j]['_high_value'] = 
						htmlspecialchars($this -> q_param["high_{$searchPropertyArr[$j]['PROPERTY_ID']}_"], ENT_QUOTES);
					//Формируется SQL 
					$intervalStr .= ($intervalStr ? ' and ' : '');
					$intervalStr .= 
						varcharToFloat('PP.VALUE_PROPERTY') .' < '.htmlspecialchars($this -> q_param["high_{$searchPropertyArr[$j]['PROPERTY_ID']}_"], ENT_QUOTES);
				}
				if ($intervalStr) {
					//Формируется SQL 
					$propertySQL .= "(PP.PROPERTY_ID = ".intval($searchPropertyArr[$j]['PROPERTY_ID'])." and {$intervalStr}) or ";
					++$_flag_;
					++$_count0_;
				}
				$searchPropertyArr[$j]['_interval'] = 1;
			}
			//строка
			else {
				if (isset($this -> q_param["{$searchPropertyArr[$j]['PROPERTY_ID']}_"])&&
					$this -> q_param["{$searchPropertyArr[$j]['PROPERTY_ID']}_"] != '') {
					//Сохраняется параметр поиска
					$searchPropertyArr[$j]['_one_value'] = 
						htmlspecialchars($this -> q_param["{$searchPropertyArr[$j]['PROPERTY_ID']}_"], ENT_QUOTES);
					//Формируется SQL 
					$propertySQL .= 
						"(PP.PROPERTY_ID = ".intval($searchPropertyArr[$j]['PROPERTY_ID'])." and PP.VALUE_PROPERTY LIKE '%".
						htmlspecialchars($this -> q_param["{$searchPropertyArr[$j]['PROPERTY_ID']}_"], ENT_QUOTES)."%') or ";
					++$_flag_;
					++$_count0_;
				}
				$searchPropertyArr[$j]['_value'] = 1;
			}
			
		elseif ($searchPropertyArr[$j]['PROPERTY_TYPE'] && !empty($valueArr))
	   		foreach ($valueArr as $value)
				if ($searchPropertyArr[$j]['PROPERTY_ID'] == $value['PROPERTY_ID']) {
		   			if ($value['PV_ID'] == $this -> q_param["{$searchPropertyArr[$j]['PROPERTY_ID']}_"]) {
						$propertySet .= intval($value['PV_ID']).", ";
		   				$value['_selected'] = 1;
		   				++$_flag_;
		   				++$_count12_;
		   			}
		   			$searchPropertyArr[$j]['_value_loop'][] = $value;
	   			}

	// Поиск по характеристикам
	$contentArr0 	= array();
	$contentArr12 	= array();
	
	if ($propertySet) {
		
		$tempContentArr = sql_select("
			select distinct
				PP.CONTENT_ID as CONTENT_ID,
				count(*) as LINECOUNT
			from
				PRODUCT_PROPERTY PP,
				PRODUCT_PROPERTY_VALUE PPV
			where
				PPV.PROPERTY_VALUE_ID in (".substr($propertySet, 0, strlen($propertySet) - 2).") and
				PPV.PRODUCT_PROPERTY_ID = PP.PRODUCT_PROPERTY_ID
			group by PP.CONTENT_ID
			having count(*) >= ".($this -> q_param['searchType'] == 'or' ? 1 : $_count12_));

		foreach($tempContentArr as $tempContent) $contentArr12[] = $tempContent['CONTENT_ID'];
	}

	if ($propertySQL) {

		$tempContentArr = sql_select("
			select distinct 
				PP.CONTENT_ID as CONTENT_ID,
				count(*) as LINECOUNT
			from 
				PRODUCT_PROPERTY PP
			where 
				".substr($propertySQL, 0, strlen($propertySQL) - 3)."
			group by 
				PP.CONTENT_ID
			having count(*) >= ".($this -> q_param['searchType'] == 'or' ? 1 : $_count0_));

		foreach($tempContentArr as $tempContent) $contentArr0[] = $tempContent['CONTENT_ID'];
	}

	if ($propertySQL && $propertySet)	{

		// Хотя бы одна характеристика
		if ($this -> q_param['searchType'] == 'or') {
		
			$contentArr = array_merge($contentArr0, $contentArr12);
			$contentArr = array_unique($contentArr);

		// Все характеристики
		} else	$contentArr = array_intersect($contentArr0, $contentArr12);
	}
	elseif ($propertySQL)	$contentArr = $contentArr0;
	elseif ($propertySet)	$contentArr = $contentArr12;
				
	if (!$contentArr) {
	
		if ($propertySet || $propertySQL) $propertySQL = '1=0';
	
	} else $propertySQL = ' P.CONTENT_ID in ('.implode(', ', $contentArr).') ';

	$this -> tmpl -> setLoop('_property_loop', $searchPropertyArr);
	
	return $propertySQL;
  }

  /***************************** getCommonPropertyArr *******************/
  function getCommonPropertyArr($productTypeArr, 			// типы товаров
  								$flagName = 'IS_IN_LIST'  	// модифицировать для поиcка
  							  ) {
  	/* 
  		Возвращает массив общих (IS_IN_LIST) или участвующих в поиске (IS_IN_SEARCH) характеристик 
  		для множества типов товаров.
  	*/
  	
  	$productTypeSet = (intval($this -> q_param['pt_id_']) ? 
  		intval($this -> q_param['pt_id_']) : $this -> getSet($productTypeArr, 'PRODUCT_TYPE_ID'));

	if (!$productTypeArr) return array();
	
	$commonPropertyArr = 
		sql_select("select
					      PTPR.PROPERTY_ID,
					      count(PTPR.PROPERTY_ID) as C,
					      PR.NAME as HEADER_NAME,
						  PR.NAME as PROPERTY_NAME,					      
					      PR.PROPERTY_TYPE,
					      PR.MESURE_UNITS,
					      PR.IS_NUMBER
					from
					    PRODUCT_TYPE_PROPERTY PTPR,
					    PROPERTY PR
					where
					     PTPR.PRODUCT_TYPE_ID in ({$productTypeSet}) and
					     PTPR.{$flagName} = 1 and
					     PTPR.PROPERTY_ID = PR.PROPERTY_ID and
					     PR.LANG_ID = ".intval($this -> lang_id)."
					group by
						PTPR.PROPERTY_ID,
						PTPR.PROPERTY_ORDER,
						PR.NAME,			      
						PR.PROPERTY_TYPE,
						PR.MESURE_UNITS,
						PR.IS_NUMBER
					having count(PTPR.PROPERTY_ID) = ".($this -> q_param['pt_id_'] ? '1' : count($productTypeArr))."
					order by PTPR.PROPERTY_ORDER");
  	
  	return $commonPropertyArr;
  }

  /**Возвращает фрагменты SQL-запроса для выборки списка товаров
   * @return string
   */
  function getSQLArr($commonPropertyArr, $selectSQL='', $fromSQL = '', 	$whereSQL = '', $orderSQL='') {

	if ( intval($this -> q_param['pt_id_']) ){
		$whereSQL .= ' and P.PRODUCT_TYPE_ID = '.intval($this -> q_param['pt_id_']).'';
	}

	$headerArr = $this -> getHeaderArr($commonPropertyArr);
	//Заполнение URL для заголовков у которых разрешена сортировка
	for($i = 0; $i < count($headerArr); $i++)
		if ($headerArr[$i]['URL']) $headerArr[$i]['URL'] = make_query_string(array("ord{$this -> tarea_id}" => $i));

	//Сортируемый столбец
	if ($this -> q_param['ord'])
		if (strlen($this -> q_param['ord']) >= 3) {
			$sortType = ' desc';
			$sortedRow = substr($this -> q_param['ord'], 0, strlen($this -> q_param['ord']) - 2);
			$headerArr[$sortedRow]['ARROW_UP'] = 1;
			$headerArr[$sortedRow]['URL'] = make_query_string(array('ord'.$this -> tarea_id => $sortedRow));
		} else {
			$sortedRow = $this -> q_param['ord'];
			$headerArr[$sortedRow]['ARROW_DOWN'] = 1;
			$headerArr[$sortedRow]['URL'] = make_query_string(array('ord'.$this -> tarea_id => $sortedRow.'00'));
		}
	
    $this -> tmpl -> setLoop('HEADER_NAME_LOOP', $headerArr);

	//сортировка списка товаров с общими характеристиками
	if ($headerArr[$sortedRow]['PROPERTY_ID']) {

		   if (!$headerArr[$sortedRow]['PROPERTY_TYPE']) {
		   		
                $valueProperty = ($headerArr[$sortedRow]['IS_NUMBER']) ? varcharToFloat('PP.VALUE_PROPERTY') : 'PP.VALUE_PROPERTY';

				if (strstr($this -> view_param['view_mode'], 'search')) {

					$selectSQL 	.=  ", $valueProperty as VALUE ";
					$fromSQL	 .= "
									left join
									    PRODUCT_PROPERTY PP
									on
									     PP.CONTENT_ID = P.CONTENT_ID and
									   	 PP.PROPERTY_ID = ".intval($headerArr[$sortedRow]['PROPERTY_ID']);

				} elseif ($this -> view_param['view_mode'] == 'list') {
	
					$selectSQL 	=  "select
									      P.*,
									      $valueProperty as VALUE ";
					$fromSQL 	=  "from
									    PRODUCT P,
									    CONTENT_MAP CM
									left join
									    PRODUCT_PROPERTY PP
									on
									     CM.CONTENT_ID = PP.CONTENT_ID and
									     PP.PROPERTY_ID = ".intval($headerArr[$sortedRow]['PROPERTY_ID'])."
									where
									     CM.INF_BLOCK_ID = ".intval($this -> block_id)." and
									     CM.CONTENT_ID = P.CONTENT_ID and
									     P.LANG_ID = ".intval($this -> lang_id)." and
									     P.VERSION = ".intval($this -> version);
				}
				
		   } elseif ($headerArr[$sortedRow]['PROPERTY_TYPE'] == 1) {
				
				if (strstr($this -> view_param['view_mode'], 'search')) {

					$selectSQL	 .= ",  PV.NAME as VALUE ";
					$fromSQL	 .= "
									left outer join
									    PRODUCT_PROPERTY PP
									on
								      PP.PROPERTY_ID = ".intval($headerArr[$sortedRow]['PROPERTY_ID'])." and
									  PP.CONTENT_ID = P.CONTENT_ID
									left outer join
									    PRODUCT_PROPERTY_VALUE PPV
									on
									  PPV.PRODUCT_PROPERTY_ID = PP.PRODUCT_PROPERTY_ID
									left outer join
									    PROPERTY_VALUE PV
									on
									   PV.PROPERTY_VALUE_ID = PPV.PROPERTY_VALUE_ID ";
					$whereSQL	.= " and (PV.LANG_ID = ".intval($this -> lang_id)." or PV.LANG_ID is NULL) ";

				} elseif ($this -> view_param['view_mode'] == 'list') {
					
					$selectSQL	 = "select
									      P.*,
									      PV.NAME as VALUE ";
					$fromSQL	 = "from
									    CONTENT_MAP CM,
									    PRODUCT P
									left outer join
									    PRODUCT_PROPERTY PP
									on
								      PP.PROPERTY_ID = ".intval($headerArr[$sortedRow]['PROPERTY_ID'])." and
									  PP.CONTENT_ID = P.CONTENT_ID
									left outer join
									    PRODUCT_PROPERTY_VALUE PPV
									on
									  PPV.PRODUCT_PROPERTY_ID = PP.PRODUCT_PROPERTY_ID
									left outer join
									    PROPERTY_VALUE PV
									on
									   PV.PROPERTY_VALUE_ID = PPV.PROPERTY_VALUE_ID
									where
									     CM.INF_BLOCK_ID = ".intval($this -> block_id)." and
										 CM.CONTENT_ID = P.CONTENT_ID and
									     P.LANG_ID = ".intval($this -> lang_id)." and
									     P.VERSION = ".intval($this -> version)." and
									     (PV.LANG_ID = ".intval($this -> lang_id)." or PV.LANG_ID is NULL) ";					
				}
		   }
    	   
    	   $orderSQL 	=  " order by VALUE $sortType";  

	//сортировка списка товаров по полям товара		
	} else {
			switch ($headerArr[$sortedRow]['HEADER_NAME']) {
				case 'Название' :  $field =	'P.TITLE'; break;
				case 'Цена'  	:  $field = 'P.PRICE'; break;
				default         :  $field = 'P.TITLE';
			}

			if ($this -> view_param['view_mode'] == 'list') {
				$selectSQL	 = "select
								      P.* ";
				$fromSQL	 = "from
								    PRODUCT P,
								    CONTENT_MAP CM
								where
								     CM.INF_BLOCK_ID = ".intval($this -> block_id)." and
								     CM.CONTENT_ID = P.CONTENT_ID and
								     P.LANG_ID = ".intval($this -> lang_id)." and
								     P.VERSION = ".intval($this -> version);
			}			
			
			$orderSQL 	=  " order by {$field} $sortType";  
	}
	
	return array('selectSQL' => $selectSQL, 'fromSQL' => $fromSQL.$whereSQL, 'orderSQL' => $orderSQL);
  }

  /**
   * Переопределяется кэширование модуля.
   * Отключается в случае сравнения товаров.
   * @return mixed
   */
  function get_hash_code() {
  
	if ($this -> version || 
		$this -> q_param['action'] == 'compare') return false;
    
    $filename = $this -> block_id.$this -> lang_id;
    foreach ($this->view_param as $key => $value) $filename .= $key.$value;
    
    if (is_array($this -> q_param))
        foreach($this -> q_param as $key => $value)	$filename .= $key.$value.$_GET['print'].$_POST['print'];
	
	return md5($filename);    
  }

}
?>